/*
 * Author: http://www.redwolf-soft.com
 * All Rights Reserved
 * 
 * 2013.11
 *   
 * */

package com.redwolfsoft.libshoppingserver.brand;



import net.sf.json.JSONObject;


public class BrandInfo {
	public final static String TAG = "BrandInfo";
	
	
	//public int id = -1;//品牌id
	public String id = null;//品牌id
	public String mDisplayName = null;	//品牌要在客户端显示的名称	
	public String homePicUrlStr = null;//首页图片链接
	public String homePicFileName = null;//首页图片文件名称	
	public String homePicFilePath = null;//首页图片保存路径
	//public String mBrandStoryUrl = null;//品牌故事链接
	public String mLogoUrl = null;//品牌logo，用于收藏
	
	//public List<BrandShopInfo> mBrandShopInfoList = null;//专卖店列表（所有国家）
	//public List<BrandAuthorizedShopInfo> mAuthorizedShopList = null;//授权店列表（所有国家）
	
	/**
	 * 用于收藏
	 * */
	public BrandInfo(String id,String name,String logoUrl)
	{
		this.id=id;
		this.mDisplayName = name;
		this.mLogoUrl = logoUrl;
	}
	
	/**
	 * filepath对于服务器端而言，无意义，可以将filepath指定为空
	 * */
	public BrandInfo(String id, String name, 
			String url,String filepath,
			String filename
			//String brandStoryUrl
			//,List<BrandAuthorizedShopInfo> list
			//, List<BrandShopInfo> list2
			)
	{
		this.id =id;
		mDisplayName = name;
		homePicUrlStr = url;	
		homePicFileName = filename;
		homePicFilePath = filepath;
	//	mBrandStoryUrl=brandStoryUrl;
		//mAuthorizedShopList = list;
		//mBrandShopInfoList = list2;
	}
	/**
	 * 需要在客户端额外指定homePicFilePath
	 * 即使用JSONObject构建后，再指定homePicFilePath的值
	 * */
	public BrandInfo(JSONObject obj)
	{
		if(obj==null)
		{
			//Log.w(TAG, "JSONObject is null");
			return;
		}
		//try {		
			id = obj.getString("id");
			mDisplayName = obj.getString("mDisplayName");
			homePicUrlStr = obj.optString("homePicUrlStr");
			homePicFileName = obj.optString("homePicFileName");
			homePicFilePath = obj.optString("homePicFilePath");
			//mBrandStoryUrl=obj.optString("mBrandStoryUrl");
			mLogoUrl=obj.optString("mLogoUrl");
			/*ShoppingCenter
			mBrandShopInfoList = new ArrayList<BrandShopInfo>();
			JSONArray array1 = obj.getJSONArray("mBrandShopInfoList");
			for(int i=0;i<array1.size();i++)
			{				
				mBrandShopInfoList.add(new BrandShopInfo(array1.getJSONObject(i)));
			}
			
			mAuthorizedShopList = new ArrayList<BrandAuthorizedShopInfo>();
			JSONArray array2 = obj.getJSONArray("mAuthorizedShopList");
			for(int i=0;i<array1.size();i++)
			{				
				mAuthorizedShopList.add(new BrandAuthorizedShopInfo(array2.getJSONObject(i)));
			}	*/	
			
		/*} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}*/
	}
	
	public JSONObject toJsonObject()
	{
		JSONObject obj = new JSONObject();
		//JSONObject obj2 = new JSONObject();
		//try {
			obj.put("id", id);
			obj.put("mDisplayName", mDisplayName);
			obj.put("homePicUrlStr", homePicUrlStr);
			obj.put("homePicFileName", homePicFileName);
			obj.put("homePicFilePath", homePicFilePath);
			//obj.put("mBrandStoryUrl", mBrandStoryUrl);
			obj.put("mLogoUrl", mLogoUrl);
		/*	
			JSONArray array1 = new JSONArray();
			for(int i=0;i<mBrandShopInfoList.size();i++)
			{
				array1.add(i,mBrandShopInfoList.get(i).toJsonObject());
			}
			obj.put("mBrandShopInfoList", array1);
			
			JSONArray array2 = new JSONArray();
			for(int i=0;i<mAuthorizedShopList.size();i++)
			{
				array2.add(i,mAuthorizedShopList.get(i).toJsonObject());
			}
			obj.put("mAuthorizedShopList", array2);
			*/
			//obj2.put(TAG, obj);
		/*} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}*/
		return obj;
		
	}
	
}
